package com.admin.common.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * ClassName: ValidationUtils
 * Function:  参数校验工具
 * Date:      2018-11-19 14:40
 * author     likaixuan
 * version    V1.0
 */
public class ValidationUtils {

	public static final String MOBILE_PATTERN = "^(1[3-9])\\d{9}$";
    /**
     * @Function 判断是否是手机号
     * @author   likaixuan
     * @Date     2018-11-19 14:41
     * @return   boolean
     */
    public static boolean isPhone(String phone) {

        Pattern pattern = Pattern.compile(MOBILE_PATTERN);
        Matcher matcher = pattern.matcher(phone);
        if (matcher.matches()) {
            return true;
        }
        return false;
    }

    //手机校验
    public static boolean checkMobile(String mobile) {
        String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";
        if (mobile.length() != 11) {
            return false;
        } else {
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(mobile);
            boolean isMatch = m.matches();
            if (!isMatch) {
                return false;
            }
            return true;
        }
    }
}
